﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the "Categories" table that holds all categories.				*
********************************************************************************************************************/

CREATE TABLE [dbo].[Categories]
(
	ID bigint PRIMARY KEY NOT NULL IDENTITY(1,1),						/* The id of the category */
	Name nvarchar(50) NOT NULL,											/* The name of the category */
	Owner bigint NOT NULL,												/* The owner of the category */
	IsPrivate int NOT NULL DEFAULT(0),									/* O if the category is not private */
	IsApproved int NOT NULL DEFAULT(0),									/* 0 if the category is not approved */
	IsDeleted int DEFAULT(0),											/* 1 if the category is deleted */
	DateCreated datetime NOT NULL DEFAULT(CURRENT_TIMESTAMP),			/* The time the category was created */
	FOREIGN KEY (Owner) REFERENCES Users(ID),
	CONSTRAINT UniqueNameForUser UNIQUE (Name,Owner)					/* Do not allow two categories with the same name for a specific user */ 
)
